package com.example.myaop.config;

import com.example.myaop.common.APPVar;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Component
//自定义拦截器
public class UserInter implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession httpSession = request.getSession(false);
        if(httpSession!=null && httpSession.getAttribute(APPVar.SESSION_KEY) != null){
            return true;
        }
        response.sendRedirect("https://www.baidu.com");
        return false;
    }
}
